#include "tools/tcp_epoll_help.h"

int Tcpinit(char *ip_addr, char *port) {
	struct sockaddr_in addr;
	addr.sin_family = AF_INET;
	addr.sin_addr.s_addr = inet_addr(ip_addr);
	if (addr.sin_addr.s_addr == -1)
		return -1;
	addr.sin_port = htons(atoi(port));

	int sfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    int flag=1;
    setsockopt(sfd,SOL_SOCKET,SO_REUSEADDR,&flag,sizeof(int));
	int tag = bind(sfd, (struct sockaddr *)&addr, sizeof(addr));
	if (tag == -1)
		return -1;
	listen(sfd, 50);
    printf("tcp server:%s %s \n",ip_addr,port);
	return sfd;
}



int epollAdd(int epfd, int fd, struct epoll_event e_event) {
	printf("NO USE\n");
	return 0;
}

int epollAddFd_In(int epfd, int fd) {
	struct epoll_event evt;
	evt.events = EPOLLIN;
	evt.data.fd = fd;
	return epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &evt);
}

int epollDel(int epfd, int fd) {
	return epoll_ctl(epfd, EPOLL_CTL_DEL, fd, NULL);
}